home *** CD-ROM | disk | FTP | other *** search
- Path: dispatch.news.demon.net!demon!fe-line.demon.co.uk
- From: faye@fe-line.demon.co.uk (Faye Pearson)
- Newsgroups: comp.lang.c,alt.bbs.proboard
- Subject: Re: Needed: Centering Procedure that ignores escape sequences
- Date: Wed, 14 Feb 1996 23:05:25 GMT
- Organization: fe-line
- Message-ID: <31224b3d.1590682@158.152.254.254>
- References: <4fog4q$24v@news.mountain.net>
- NNTP-Posting-Host: fe-line.demon.co.uk
- X-NNTP-Posting-Host: fe-line.demon.co.uk
- X-Newsreader: Forte Agent .99c/16.141
-
- matt.jenkins@westvirginia.com (Light Chaser) wrote:
-
- >I spent a whole day trying to come up with a simple and small
- >centering routine. I came up with one, but then ran into the problem
- >that I have to ignore escape sequences. My BBS software, ProBoard,
- >supports only certain functions (which are listed at the end of this
- >message). I want something where I can do:
- >center("\n\2This \3text \5contains \1escape \6sequences\t\n");
-
- almost all proboards printf formatting escapes are single characters,
- if you wanted to just cope with that, you could use
-
- void centre(char*string)
- {
- char *ptr;
- int esccount,xpos;
- char spaces[41];
-
- for((esccount=0),(ptr=string-1);ptr=strchr(ptr+1,'\\');esccount++);
- xpos=40-strlen(string)/2-esccount;
- memset(spaces,' ',xpos-1);
- spaces[xpos]='\0';
- printf("%s%s",spaces,string); // Don't use GotoXY as it won't work for
- // ASCII users.
- }
-
- This isn't a piece of code I have used, but I can't see why it
- wouldn't work...as long as the string to be output (-esc chars) is
- less than 80 characters long.
-
-
- Faye
- --
- Home of Fe-line Software, http://www.win-uk.net/~fe-line
- PSN *UK* RC ftp://ftp.win-uk.net/pub/users/fe-line/
- mailto:sysops@fe-line.demon.co.uk
- ProBoard *UK* Registration & Support Site
-